package work.mediway.mdm.biz.listener;

import com.mediway.hos.messgateway.model.entity.MessageEntity;
import com.mediway.hos.messgateway.service.MessageEntityService;

import org.springframework.context.event.EventListener;
import org.springframework.lang.NonNull;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Component;

import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import work.mediway.mdm.core.constant.MdmConstant;
import work.mediway.mdm.biz.event.entity.DictPushEvent;

/**
 * @author zhongyj <1126834403@qq.com><br/>
 * @date 2021/11/17
 */
@Component
@Slf4j
@RequiredArgsConstructor
public class DataPushEventListener {

    private final MessageEntityService messageEntityService;

    @EventListener
    @Async(MdmConstant.MDM_THREAD_POOL)
    public void onDataPush(@NonNull DictPushEvent event) {
        MessageEntity messageEntity = event.getMessageEntity();
        // 调用消息转发
        messageEntityService.insertMessageEntity(messageEntity);
        log.info("消息【{}】进入发送队列", messageEntity.getTypeId());
    }
}
